﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MotaWeb.Models.Interfaces;
using System.Web.Security;
using MotaWeb.Security;
using System.Text;

namespace MotaWeb.Models
{
    public class MotaSiteUser : ISiteUser
    {
        #region Private Members
        #endregion

        #region Construction
        public MotaSiteUser()
        {

        }

        public MotaSiteUser(MembershipUser user, IRoleService roleService)
        {
            UserName = user.UserName;
            Email = user.Email;
            Roles = roleService.GetRolesForUser(user.UserName);
        }

        public MotaSiteUser(string userName, string email, string firstName, string lastName, Guid providerUserKey)
        {
            UserName = userName;
            Email = email;
            FirstName = firstName;
            LastName = lastName;
            ProviderUserKey = providerUserKey;
        }
        #endregion

        #region ISiteUser interface
        public int Id { get; set; }
        public string UserName { get; set; }
        public string Email { get; set; }
        public Guid ProviderUserKey { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string[] Roles { get; set; }
        public string RolesDisplay
        {
            get
            {
                string retVal = string.Empty;

                StringBuilder sb = new StringBuilder();
                foreach (string role in Roles)
                {
                    sb.AppendFormat("{0},", role);
                }
                
                if (sb.Length > 0)
                {
                    retVal = sb.ToString().Substring(0, sb.Length - 1);
                }

                return retVal;
            }
        }
        #endregion

        
    }
}
